#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>

using namespace std;

int ret = 0;
bool visite[20][20];

int dx[4] = { 0 , 0 , 1 , -1 };
int dy[4] = { 1 , -1 , 0 , 0 };

void dfs(vector<vector<int>>& grid, int row, int col, int value)
{
    for (int i = 0; i < 4; ++i)
    {
        int x = dx[i] + row;
        int y = dy[i] + col;

        if (x >= 0 && x < grid.size() && y >= 0 && y < grid[0].size()
            && visite[x][y] == false && grid[x][y] != 0)
        {
            visite[x][y] = true;
            ret = max(ret, value + grid[x][y]);
            dfs(grid, x, y, value + grid[x][y]);
            visite[x][y] = false;
        }
    }
}

int getMaximumGold(vector<vector<int>>& grid) {
    int m = grid.size();
    int n = grid[0].size();

    for (int i = 0; i < m; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if (grid[i][j] != 0)
            {
                visite[i][j] = true;
                ret = max(ret, grid[i][j]);
                dfs(grid, i, j, grid[i][j]);
                visite[i][j] = false;
            }
        }
    }

    return ret;
}


int main()
{

	return 0;
}